package com.basker.pisces.core.meta;

public class ReferenceField extends DataObjectField implements IReferenceField {

    private IDataField refrenceIdField;

    public ReferenceField(String name, String displayName, IDataObjectMeta objectMeta, IDataField refrenceIdField) {
        super(name, displayName, objectMeta);

        this.refrenceIdField = refrenceIdField;
    }

    @Override
    public IDataField getReferenceIdField() {
        return refrenceIdField;
    }

    @Override
    public final void setValue(Object dataObject, Object value) {
        this.internalSetValue(dataObject, value);

        Object pkValue = value != null ? this.getDataObjectMeta().getPkField().getValue(value) : null;
        this.getReferenceIdField().setValue(dataObject, pkValue);
    }

    protected void internalSetValue(Object dataObject, Object value) {
        super.setValue(dataObject, value);
    }

}
